from datetime import datetime
import hashlib
from langchain_core.tools import tool
import requests

def md5_encrypt(text:str) -> str:
    md5 = hashlib.md5()
    md5.update(text.encode('utf-8'))

    return md5.hexdigest().upper()

def requests_token_url(token_url_param):
    url = "http://192.168.22.93:7007/api/public/token"
    response=requests.post(url,json=token_url_param)
    return response


def get_token(user_id):
    timestamp = str(int(datetime.now().timestamp()))

    #md5加密    
    sign = md5_encrypt(user_id + timestamp + 'token')

    token_url_param = {
        "sign":sign,
        "timestamp": str(timestamp),
        "usercode":user_id
    }
    persinal_data=requests_token_url(token_url_param)
    
    return persinal_data.json()['data']